using UnityEngine;

namespace Gj
{
    public class SoundSourceHelper : NodeHelper
    {
        public AudioSource source;
        public bool invert;
        public bool auto;
        private bool allow;

        protected override BindDataType bindDataType => BindDataType.Bool;

        protected override void Start()
        {
            base.Start();
            if (auto)
            {
                allow = true;
                source.Play();
            }
        }

        protected override void BindData(bool b)
        {
            var _allow = invert ? !b : b;
            if (_allow != allow)
            {
                if (_allow)
                    source.Play();
                else
                    source.Stop();
            }

            allow = _allow;
        }
    }
}